<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script>
			function deepCopy(obj) {
				if (obj instanceof Array) {
					var temp = [];
					for (var i = 0; i < obj.length; i++) {
						temp[i] = deepCopy(obj[i]);
					}
				} else {
					var temp = {};
					if (obj.id == "root") {
						temp.root = {};
						temp.root.data = {};
						temp.root.data.text = obj.title;
						temp.root.data.id = obj.id;
						temp.root.data.created = new Date().getTime();
						temp.root.children = deepCopy(obj.children);
					} else {
						temp.data = {};
						temp.data.text = obj.title;
						temp.data.id = obj.id;
						if (obj.image) {
							temp.data.image = obj.image.url;
							temp.data.imageSize = {};
							temp.data.imageSize.width = obj.image.w;
							temp.data.imageSize.height = obj.image.h;
						}
						if (obj.link) {
							temp.data.hyperlink = obj.link.value;
							temp.data.hyperlinkTitle = obj.link.title;
						}
						if (obj.note) {
							temp.data.note = obj.note;
						}

						temp.data.created = new Date().getTime();
						if (obj.children) {
							temp.children = deepCopy(obj.children);
						}

					}
				}

				return temp;
			}


			var abc = deepCopy(obj);
			console.log(abc);
			console.log(JSON.stringify(abc));
		</script>
	</body>
</html>
